<template>
    <el-dialog title="Salary Entry" :close-on-click-modal="false" :visible.sync="visible">
        <el-form :model="dataForm" ref="dataForm" label-width="80px">
            <el-form-item label="year">
                <el-input v-model="dataForm.year" placeholder="Fill in the year"></el-input>
            </el-form-item>
            <el-form-item label="month">
                <el-input v-model="dataForm.month" placeholder="Fill in the month"></el-input>
            </el-form-item>
            <el-form-item label="realName">
                <el-input v-model="dataForm.realName" placeholder="Fill in the realName"></el-input>
            </el-form-item>
            <el-form-item label="mobile">
                <el-input v-model="dataForm.mobile" placeholder="Fill in the mobile"></el-input>
            </el-form-item>
            <el-form-item label="basicSalary">
                <el-input v-model="dataForm.basicSalary" placeholder="Fill in the basicSalary"></el-input>
            </el-form-item>
            <el-form-item label="postSalary">
                <el-input v-model="dataForm.postSalary" placeholder="Fill in the postSalary"></el-input>
            </el-form-item>
            <el-form-item label="mealSalary">
                <el-input v-model="dataForm.mealSalary" placeholder="Fill in the mealSalary"></el-input>
            </el-form-item>
            <el-form-item label="travelSalary">
                <el-input v-model="dataForm.travelSalary" placeholder="Fill in the travelSalary"></el-input>
            </el-form-item>
            <el-form-item label="overtimeSalary">
                <el-input v-model="dataForm.overtimeSalary" placeholder="Fill in the overtimeSalary"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">submit</el-button>
                <el-button @click="visible = false">cancel</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          year: '',
          month: '',
          realName: '',
          mobile: '',
          basicSalary: '',
          postSalary: '',
          mealSalary: '',
          travelSalary: '',
          overtimeSalary: ''
        }
      }
    },
    methods: {
      init () {
        console.log('123456')
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
        })
      },
      onSubmit () {
        console.log(this.dataForm)
        this.$http({
          url: this.$http.adornUrl(`/edu/tedusalary/onSubmit`),
          method: 'post',
          data: this.dataForm
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: 'Operation succeeded',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      }
    }
  }
</script>